<?php

namespace App\Models\Common\English;
use Illuminate\Database\Eloquent\Model;
use Cache;

class EnCollOption extends Model{
    //设置表的类型和表名
    protected $table='coll_options';
    protected $primaryKey='id';
    public $timestamps = false;
    protected $fillable = [
        'en_opt_name', 'opt_id', 'sign', 'opt_sort'
    ];

    /**
     * 说明:获取指定菜单例数据
     * $sign:指定菜单的标示
     * @return array
     */
    public static function getOption($sign){
        $option=self::where('sign', $sign)->orderBy('opt_id','asc')->get();
        $option = setSort($option,'opt_sort');
        $optionArray=array();
        foreach($option as $key=>$value){
            $optionArray[]=array('text'=>$value['en_opt_name'],'value'=>$value['opt_id']);
        }
        return $optionArray;
    }

    /**
     * 说明：获取指定的选项id的中文值
     * $opt_id:选项编号
     * $sign:选项标识
     * @return： 选项名称
     */
    public static function getOptionName($opt_id,$sign){
        $options=array();
        if (Cache::has('options_en')) {
            $options= Cache::get('options_en');
        }else {
            $options = self::get()->toArray();
            Cache::forever('options_en', $options);
        }
        foreach($options as $v){
            if($v['sign'] == $sign && $v['opt_id'] == $opt_id){
                return $v['en_opt_name'];
            }
        }
        return '';
    }
}